#define _CRT_SECURE_NO_WANINGS 1
#pragma warning(disable: 4996)
int getint(char c)
{
    switch (c)
    {
    case 'I':
        return 1;
    case 'V':
        return 5;
    case 'X':
        return 10;
    case 'L':
        return 50;
    case 'C':
        return 100;
    case 'D':
        return 500;
    case 'M':
        return 1000;
    default:
        return 0;
    }
}
int romanToInt(char* s) {
    int ret = 0;
    if (s[0] == '\0')
    {
        return 0;
    }
    if (s[1] == '\0')
    {
        return getint(s[0]);
    }
    for (int i = 0; s[i] != '\0'; i++)
    {
        if (getint(s[i + 1]) > getint(s[i]))
        {
            ret = ret - getint(s[i]);
        }
        else
        {
            ret = ret + getint(s[i]);
        }

    }
    return ret;
}
int strStr(char* haystack, char* needle) {
    for (int i = 0; i < strlen(haystack); i++)
    {
        if (haystack[i] == needle[0])
        {
            int p = i;
            int k = 0;
            while (needle[k] != '\0')
            {

                if (needle[k] != haystack[p])
                {
                    break;
                }
                if (needle[k + 1] == '\0')
                {
                    break;
                }
                k++;
                p++;
            }
            if (needle[k] == haystack[p])
            {
                return i;
            }
        }
    }
    return -1;
}
int lengthOfLastWord(char* s) {
    int sz = strlen(s);
    for (int i = sz - 1; i >= 0; i--)
    {
        if (s[i] != ' ')
        {
            int j = i;
            int n = 0;
            while (j != -1 && s[j] != ' ')
            {
                n++;
                j--;

            }
            return n;
        }
    }
    return 0;
}
int searchInsert(int* nums, int numsSize, int target) {
    if (target <= nums[0])
    {
        return 0;
    }
    if (numsSize == 1)
    {
        if (nums[0] >= target)
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
    for (int i = 0; i < numsSize - 1; i++)
    {

        if (nums[i] == target)
        {
            return i;
        }
        if (nums[i] < target && nums[i + 1] >= target)
        {
            return i + 1;
        }
    }
    return numsSize;
}